(function() {

this.pasta = this.pasta || {};
this.pasta.webgui = this.pasta.webgui || {};

this.pasta.webgui.DropDownBox = pasta.webgui.Control.extend(
{
	init : function() 
	{
		this._super();
		
		this.caption = "";
		this.canvas.style.overflow = "hidden";
		
		var obj = this;
		
		this.obj = document.createElement("select");
		this.obj.id = this.cid + "_select";
		this.obj.style.position = "absolute";
		this.obj.style.left = "0px";
		this.obj.style.top = "0px";
		this.obj.style.width = "100%";
		this.obj.style.height = "100%";
		this.obj.onchange = function(e) { if (!e) e = window.event; obj.doObjChange(); };
		this.canvas.appendChild(this.obj);
		
		this.setHeight(20);
		
		this._onSelect = null;
	},
	
	doObjChange : function()
	{
		if (this._onSelect != null)
			this._onSelect.callHandler(this, this.obj.value);
	},
	
	addItem : function(id, value)
	{
		this.obj.options[this.obj.options.length] = new Option(value, id);
	},
	
	clear : function()
	{
		this.obj.options.length = 0;
	},
	
	//------------------ Event Handler -----------------
	
	//------------------ Setter & Getter -----------------
	
	getItemLength : function()
	{
		return this.obj.options.length;
	},
	
	getSelectedId : function()
	{
		return this.obj.value;
	},
	
	setSelectedId : function(data)
	{
		this.obj.value = data;
	},
	
	getSelectedCaption : function()
	{
		var result = null;
		
		if (this.obj.options[this.obj.options.selectedIndex] != null)
			result = this.obj.options[this.obj.options.selectedIndex].text;
		
		return result;
	},
	
	setHeight : function(data)
	{
		this._super();
		
		if (this.obj != null)
			this.obj.style.height = data + "px";
	},
	
	//--------------------------- Event -------------------------
	
	getOnSelect : function()
	{
		if (this._onSelect == null)
			this._onSelect = new pasta.util.EventObj();
		
		return this._onSelect;
	},
});

})();